export function classNames(...classes: unknown[]): string {
  return classes.filter(Boolean).join(' ');
}

export function getSubdomains(domain = window.location.hostname): string {
  const subdomains = [];
  let currentSubdomain = '';

  // 将域名分割成单个字符
  const chars = domain.split('');

  // 遍历字符数组
  for (let i = 0; i < chars.length; i++) {
    currentSubdomain += chars[i];

    // 当遇到'.'字符时，检查当前子域名是否有效
    if (chars[i] === '.') {
      // 移除最后的'.'字符
      if (currentSubdomain[currentSubdomain.length - 1] === '.') {
        currentSubdomain = currentSubdomain.slice(0, -1);
      }

      // 添加有效子域名到数组
      if (currentSubdomain) {
        subdomains.push(currentSubdomain);
      }

      currentSubdomain = '';
    }
  }

  // 移除最后的'.'字符
  if (currentSubdomain[currentSubdomain.length - 1] === '.') {
    currentSubdomain = currentSubdomain.slice(0, -1);
  }

  // 添加最后的子域名
  if (currentSubdomain) {
    subdomains.push(currentSubdomain);
  }

  return subdomains[0];
}

// 使用示例
const domain = 'jflive.aidigitalfield.com'; // window.location.hostname
const subdomains = getSubdomains(domain);
console.log(subdomains); // 输出: 'workbench'
